<?php
namespace Api
{
    /**
     * Helper abstract class.
     * Helpers are using to create simple autoloading triats, class or function 
     * 
     * Helper can be:
     *  - Autoloading initializer for spec. module
     *      To done this, you must set 'Autohelper' value as name
     *      of helper to load.
     *      If 'Autohelper' key also can be a two dimensional array with
     *          arrays, with keys:
     *          'Helper'=>helper_class_name
     *          'Shared'=>true <- helper is in ./shared/helpers/ 
     *          'CustomDir'=> path_to_helper_directory && Shared == true
     * 
     * 
     * @author Łukasz Torba                          
     */     
     class  Helper
     {
         protected   $m_config = array();       // Configure file
         protected   $m_obj = null;             // Parent object
         
         protected   $_ObjParams = array();    // Object address parameters
         protected   $_CallAction = null;      // Action to call after helper 
          
         ////////////////////////////////////////////////
                  
            public function __construct(array $config=array(), $m_obj=null)
            {
                $this->m_config = $config;
                $this->m_obj = $m_obj;
            }
            
            public function __get($var)
            {
                if(isset($this->{'_'.$var})) return $this->{'_'.$var};
                else
                {
                    return $this->m_obj->$var;
                }
                return null;
            }
            
            /**
             * Assign obj method parameters
             * @param parameters array
            */    
            public function SetAction($action, array $param)
            {
                $this->_CallAction = $action;
                $this->_ObjParams = $param;
            }
            
            /**
             * Return action name
             */
            public function GetAction()
            {
                return $this->_CallAction;
            }          
            
            /**
             * Get obj action parameters
             * @return array with params
             */
             public function GetParameters()
             {
                return $this->_ObjParams;
             }
            
            /**
             * Check, if in parameters from address exists 
             * elements from $action array
             * @return true or false 
             * @param $action can be array of excluded or string
             */
             public function ExcludedAction($action)
             {
                if(is_array( $action ))
                {                    
                    if(array_key_exists($this->GetAction(), $action))
                    {
                        return true;
                    }
                    
                }else
                {
                    if($action ==$this->GetAction())
                    {
                        return true;
                    }
                }
                
                return false;
             }
             
     };
}
?>